package cn.tedu.store.admin.webapi.controller;

import cn.tedu.store.commons.pojo.admin.dto.AdminRoleAddNewDTO;
import cn.tedu.store.commons.pojo.admin.vo.AdminRoleListItemVO;
import cn.tedu.store.commons.web.JsonResult;

import cn.tedu.store.admin.service.IAdminRoleService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/admin_role")
@Validated
@Api(tags = "4.管理员与角色关联信息管理模块")
public class AdminRoleController {

    @Autowired
    IAdminRoleService adminRoleService;

    @PostMapping("/addNew")
    @ApiOperationSupport(order = 100)
    @ApiOperation("添加管理员与角色关联信息")
    public JsonResult addNew(@Validated AdminRoleAddNewDTO adminRoleAddNewDTO){
        adminRoleService.addNew(adminRoleAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除管理员与角色关联信息")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult delete(@PathVariable Long id){
        adminRoleService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改管理员与角色关联信息详情")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult updateById(@PathVariable Long id, AdminRoleAddNewDTO adminRoleAddNewDTO){
        log.debug("即将处理修改角色业务,参数id: {}, 角色信息: {}", id, adminRoleAddNewDTO);
        adminRoleService.updateById(id, adminRoleAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询管理员与角色关联信息列表")
    @ApiOperationSupport(order = 400)
    @GetMapping("")
    public JsonResult<List<AdminRoleListItemVO>> list(){
        log.debug("开始处理获取管理员列表的请求 参数:无");
        List<AdminRoleListItemVO> list = adminRoleService.list();
        log.debug("查询完成");
        return JsonResult.ok(list);
    }

}
